<template>
  <div v-title :data-title="title">
    <el-container>
      <el-main class="me-articles">

        <article-scroll-page v-bind="article"></article-scroll-page>

      </el-main>
    </el-container>
  </div>
</template>

<script>
import ArticleScrollPage from '@/views/common/ArticleScrollPage'
import {getArticles} from "../api/article";

export default {
  name: "BlogArchive",
  components: {
    ArticleScrollPage
  },
  created() {
    this.getArticles()
  },
  watch: {
    '$route'() {
      if (this.$route.params.year && this.$route.params.month) {
        this.article.query.year = this.$route.params.year
        this.article.query.month = this.$route.params.month
      }
    }
  },
  data() {
    return {
      article: {
        query: {
          month: this.$route.params.month,
          year: this.$route.params.year,
          authorId:this.$store.state.id
        }
      },
    }
  },
  computed: {
    title (){
      return this.currentArchive + ' - 文章归档 - 花花世界'
    }
  },
  methods: {
    getArticles() {
      let that = this
      that.loading = true
      getArticles(that.query, that.innerPage).then(data => {
        let newArticles = data.data
        if (newArticles && newArticles.length > 0) {
          that.innerPage.pageNumber += 1
          that.articles = that.articles.concat(newArticles)
        } else {
          that.noData = true
        }

      }).catch(error => {
        if (error !== 'error') {
          that.$message({type: 'error', message: '文章加载失败!', showClose: true})
        }
      }).finally(() => {
        that.loading = false
      })

    }
  }
}
</script>

<style scoped>

.el-container {
  width: 640px;
}

.el-aside {
  position: fixed;
  left: 200px;
  margin-right: 50px;
  width: 150px !important;
}

.el-main {
  padding: 0px;
  line-height: 16px;
}

.me-month-list {
  margin-top: 10px;
  margin-bottom: 10px;
  text-align: center;
  list-style-type: none;
}

.me-month-item {
  margin-top: 18px;
  padding: 4px;
  font-size: 18px;
  color: #5FB878;
}

.me-order-list {
  float: right;
}

.me-month-title {
  margin-left: 4px;
  margin-bottom: 12px;
}
</style>
